﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Module_Profile : PanelControl
{
    protected int id = Helper.getQuery("userID");
    UserBusiness ub = new UserBusiness();
    AirfareBusiness ab = new AirfareBusiness();
    protected void Page_Load(object sender, EventArgs e)
    {
        UserEntities ue = (UserEntities)Session["user"];
        lblusername.Text = ue._userName;
        txthoten.Text = ue._fullName;
        txtsdt.Text = ue._phoneNumber.ToString();
        txtdiachi.Text = ue._address;
        txtemail.Text = ue._email;
        txtdate.Text = ue._birthday;
        txtcardnum.Text = ue._cardNumber;
        txtcreditcard.Text = ue._creaitCard;
        bindBV();
        if (!IsPostBack)
        {

            
            txthoten.Enabled = false;
            txtsdt.Enabled = false;
            txtdiachi.Enabled = false;
            txtemail.Enabled = false;
            txtdate.Enabled = false;
            txtcardnum.Enabled = false;
            txtcreditcard.Enabled = false;
            btnAddNew.Text = "Sửa";
            this.an1.Visible = false;
            this.an2.Visible = false;
            
        }
    }

    public void bindBV()
    {
        GridView1.DataSource = ab.getAirfareByUser(id);
        GridView1.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        UserEntities ue = new UserEntities();
        bool flat=false;
        if (btnAddNew.Text == "Sửa")
        {
            txthoten.Enabled = true;
            txtsdt.Enabled = true;
            txtdiachi.Enabled = true;
            txtemail.Enabled = true;
            txtdate.Enabled = true;
            txtcardnum.Enabled = true;
            txtcreditcard.Enabled = true;
            this.an1.Visible = true;
            this.an2.Visible = true;
            flat = true;
        }
        if (flat)
        {
            ue._userID = id;
            ue._userName = lblusername.Text;
            ue._fullName = txthoten.Text;
            ue._phoneNumber = int.Parse(txtsdt.Text);
            ue._email = txtemail.Text;
            ue._creaitCard = txtcreditcard.Text;
            ue._cardNumber = txtcardnum.Text;
            ue._pass = Helper.EncodePass(txtpassnew.Text);
            ue._reward = 0;
            ue._roleID = "2";
            ue._birthday = txtdate.Text;
            ue._address = txtdiachi.Text;
            ue._gender = rbonam.Checked ? "1" : "0";
            if (ue._pass == "" || ue._pass == null)
            {
                txtpassnew.Focus();
                Label1.Text = "Mật khẩu không được để trống";
            }
            else if (ub.Edit(ue))
                Response.Redirect("Default.aspx");
            else
                Label1.Text = "Chưa sửa được";
        }
        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}